package com.item.controller;


import com.item.bean.Result;
import com.item.domain.TbUser;
import com.item.domain.TbUserComment;
import com.item.service.TbUserCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class TbUserCommentController {

    @Autowired
    TbUserCommentService tbUserCommentService;

    @PostMapping(value = "/tbUserComment/{limit}/{page}")
    public Result TbUserComment(
            @PathVariable(value = "limit", required = false) int limit,
            @PathVariable(value = "page", required = false) int page,
            @RequestBody(required = false) TbUserComment tbUserComment) {
        Result result = new Result();

        List<TbUserComment> tbUserComments = tbUserCommentService.findAll(limit, page, tbUserComment);

        if (tbUserComments != null) {
            result.setFlag(true);
            result.setMessage("数据请求成功");
            result.setData(tbUserComments);
        } else {
            result.setFlag(false);
            result.setMessage("数据请求失败");
            result.setData(new ArrayList<>());
        }

        return result;
    }

    @PostMapping(value = "/tbUserComment/to/list/add")
    public Integer TbUserCommentAdd(@RequestBody TbUserComment tbUserComment) {
        tbUserComment.setCreateTime(System.currentTimeMillis() + "");
        int i = tbUserCommentService.add(tbUserComment);
        return i;
    }

    @PutMapping(value = "/tbUserComment/to/list/update")
    public Integer tbUserCommentUpdate(@RequestBody TbUserComment tbUserComment) {

        int i = tbUserCommentService.update(tbUserComment);
        return i;
    }

    @DeleteMapping(value = "/tbUserComment/{id}")
    public Integer tbUserCommentDelete(@PathVariable(value = "id") int id) {

        int i = tbUserCommentService.delete(id);
        return i;
    }

}
